<?php
namespace Home\Controller;
use Think\Controller;
class UsersController extends Controller {
    public function reg(){
         
        $this->display();}

   public function register(){


        $user = D('users');
        if ($user->create()) {
            if ($_FILES['files']['error']==0) {
                $loginfo=$this->MyUpload();
                $pname=$loginfo['file']['savename'];            
            }
            else{
                $pname="defalt.jpg";
            }
            $user->photo=$pname;

            $user->telephone = trim(I('post.telephone'));
            $user->password = md5(I('post.password'));
            $user->username = I('post.username');
            $user->email = I('post.email');
            $user->createtime=date('Y-m-d H:i:s');
            if (false !== $user->add()) {
                $this->success('注册成功！', 'login');
            } else {         $this->error('数据错误');           }
            }else{
            $this->error($user->getError());}

        }//register end
        public function verify(){
        ob_clean();
//        $config =    array(
//            'fontSize'    =>    30,    // 验证码字体大小
//            'length'      =>    3,     // 验证码位数
//            'useNoise'    =>    false, // 关闭验证码杂点
//            //'fontttf' => 'msyhbd.ttf',
//           
//
//            'useImgBg' => false,
//            //'useZh' => true,
//        );
//        $Verify = new \Think\Verify($config);
        $Verify = new \Think\Verify();
        $Verify->entry();
    }

public function checkTele(){

     $t=$_GET["t"];
      $userModel = M("Users");
      $rs=$userModel->where("telephone='$t'")->select();
      if($rs) echo "手机号已存在";

    }
 public function checkAlias(){
            $u=$_GET["u"];
            $userModel = M("Users");
            $rs=$userModel->field('aliasname')->where("aliasname like '%$u%'")->limit(4)->select();
            //echo $userModel->getLastSQL();
            $this->ajaxReturn($rs);
         }
public function checkLogin(){
       
        $user=M('users');
        $map   =   array();
        $map['telephone']   =trim(I('post.telephone'));
        $map['password']    =md5(trim(I('post.password')));
        /*$map['password']    = md5($_POST['password']);*/
        $res=$user->where($map)->select();
        $state=$user->where($map)->getField('state');
        if($res==null){
            $this->error('电话或密码错误');
        }else{if($state==0){
        $_SESSION['telephone']=$map['telephone'];
            $this->success('登录成功！', '../Index/index');}
            else{
                $this->error('您的账号已被封');
            }
        }
        }


    public function MyUpload(){
    $upload = new \Think\Upload();// 实例化上传类
    $upload->maxSize   =     3145728 ;// 设置附件上传大小
    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    $upload->rootPath  =     './Public/Uploads/userphoto/'; // 设置附件上传根目录
    $upload->autoSub   = false;//关闭子目录，默认ture
    //$info=$upload->uploadOne($_FILES['file']);  //上传文件

    //$upload->savePath  =     ''; // 设置附件上传（子）目录
    $upload->savename = 'time';

    $info   =   $upload->upload();  // 上传文件 
    //$dump(info);
    if(!$info) {        $this->error($upload->getError());    }
    else{return $info;}
    
    // else{        $this->success('上传成功！');    }  


    } //MyUpload end
    }